home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / nasm095.zip / RDOFF / COLLECTN.C next >
C/C++ Source or Header  |  1997-07-27  |  730b  |  41 lines

  1. /* collectn.c    Implements variable length pointer arrays [collections]
  2.  *
  3.  * This file is public domain.
  4.  */
  5.  
  6. #include "collectn.h"
  7. #include <stdlib.h>
  8.  
  9. void collection_init(Collection * c)
  10. {
  11.   int i;
  12.  
  13.   for (i = 0; i < 32; i++) c->p[i] = NULL;
  14.   c->next = NULL;
  15. }
  16.  
  17. void ** colln(Collection * c, int index)
  18. {
  19.   while (index >= 32) {
  20.     index -= 32;
  21.     if (c->next == NULL) {
  22.       c->next = malloc(sizeof(Collection));
  23.       collection_init(c->next);
  24.     }
  25.     c = c->next;
  26.   }
  27.   return &(c->p[index]);
  28. }
  29.  
  30. void collection_reset(Collection *c)
  31. {
  32.   int i;
  33.   if (c->next) {
  34.     collection_reset(c->next);
  35.     free(c->next);
  36.   }
  37.  
  38.   c->next = NULL;
  39.   for (i = 0; i < 32; i++) c->p[i] = NULL;
  40. }
  41.